<?php require_once(dirname(__FILE__).'/../include/config.inc.php');
require_once "function.php";
/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/
$jindu= empty($jindu) ? '' : htmlspecialchars($jindu); //进度状态
$jindu=intval($jindu);
$manageid="";
if(isset($uid)){

		//有session 从数据库中读取用户名信息
	 	//$openid_str=$_SESSION['openid'];
		$sql="SELECT u.*,g.groupname  as groupname  FROM `#@__user` as u 
				   left join `#@__usergroup` as g  on u.level=g.id  
				   WHERE u.id='$uid' ";
		$row = $dosql->GetOne($sql);
			if(is_array($row) && isset($row['id'])){
				// 返回用户 id 
				$id=$row['id'];
				$_SESSION['id'] = $id;
				$userInfo=$row;
				$level=intval($row['level']);
			}
}

if($level>4){
	exit();
}



switch ($jindu)
{
case 3:
  $order_title="待接单";
  break;
case 4:
  $order_title="未完成";
  break;
case 5:
  $order_title="待评价";
  break;
case 6:
  $order_title="已评价";
  break;
default:
  $order_title="全部";
}
?>


<!DOCTYPE html>
<html>
<head>
<title><?php echo $cfg_webname;?> </title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="<?php echo $cfg_webname;?>">
<link rel="stylesheet" href="lib/weui.min.css">
<link rel="stylesheet" href="css/jquery-weui.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/demos.css">
</head>

<body ontouchstart>
<div class="top">
  <div class="user_top">
    <i>
	<?php
	 if(intval($row['level'])>1){
		 echo '<a href="manage.php">'.$userInfo['groupname'].'</a>';
	}else{
		echo $userInfo['groupname'];
	}?> 
   
    </i>
    <div class="user_top_conn"> <img src="<?php echo $userInfo['headimgurl']?>"/>
      <p><?php echo $userInfo['nickname']?></p>
       <?php if(intval($row['level'])>1){?><a  class="user_link"  href="member.php">返回用户</a><?php }?>
    </div>
  </div>
</div>
<!-- 地址信息 --> 
<!-- 报修信息 -->
<div class="main">
  <div class="weui-cells__title"><i class="fa fa-id-card-o" aria-hidden="true"></i>我的 <?php echo $order_title;?>  任务</div>
  <!--工单列表开始-->
				<?php
				$sql="SELECT * FROM `#@__order`    WHERE  is_delete=0    ";
				if(empty($jindu)){ 	$sql.="   AND  jindu>'2'  "; }else{	$sql.="  AND   jindu='$jindu'  ";	} //进度
				$sql.= "  AND FIND_IN_SET('$uid',manageid)   ORDER BY id DESC";
				$dopage->GetPage($sql,8);
				while($row = $dosql->GetArray())
				{
					/*
					进度：
					0 已经撤单
					1 报修成功
					2 客服已经联系
					3 系统已经派单
					4 工程师接单
					5 维修完成
					6 已经评价
					*/
					$orderid=$row['id'];
					$jindu2=intval($row['jindu']);
					$apply_type=$row['apply_type'];
					$apply_device=$row['apply_device'];
					


					$op_str='<a class=weui-form-preview__btn weui-form-preview__btn_primary" href="morderDetail.php?orderid='.$row['id'].'" ><i class="fa fa-navicon" aria-hidden="true"></i>详情</a>';

					

				?>
  
  <!--工单详情开始-->
  <div class="weui-form-preview">
    <div class="weui-form-preview__bd">
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">工单号：</label>
        <span class="weui-form-preview__value">
		<?php 
		if(!empty($row['poster'])) { 
		echo '<i class="fa fa-smile-o blue "></i>';
		}
		if(!empty($row['openid'])) { 
		echo '<i class="fa fa-weixin green"></i>';
		}		
		?>
        <?php echo date("Ymd",$row['post_time'])."-".$row['id']?>
        </span>   
        </div>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">单位：</label>
        <span class="weui-form-preview__value"><?php echo $row['school']?></span> </div>
        <?php if(!empty($row['truename'])){?>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">联系人：</label>
        <span class="weui-form-preview__value"><?php echo $row['truename']?></span> </div>
        <?php }?>
        <?php if(!empty($row['mobile'])){?>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">电话：</label>
        <span class="weui-form-preview__value"><a href="tel:<?php echo $row['mobile']?>"><i class="fa fa-mobile"><?php echo $row['mobile']?></a></i></span> </div>
        <?php }?>
        <?php if(!empty($row['address'])){?>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">地址：</label>
        <span class="weui-form-preview__value" id="daohang" data-orderid="<?php echo $row['id']?>"><i class="fa fa-map-marker" ><?php echo $row['address']?></i></span> </div>
        <?php }?>
         <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">服务类型：</label>
        <span class="weui-form-preview__value"><i class="fa  fa-drivers-license-o red"></i>   <?php echo getTypeName($row['apply_type'])?></span> </div>

      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">设备类型：</label>
        <span class="weui-form-preview__value"><i class="fa  fa-print red"></i>   <?php echo getDeviceName($row['apply_device'])?></span> </div> 
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">故障描述：</label>
        <span class="weui-form-preview__value"><?php echo $row['content']?></span> </div>
              <?php if(!empty($row['repairid'])){?>
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">任务类型：</label>
        <span class="weui-form-preview__value"><i class="fa  fa-print red"></i>   <?php echo getRepairMode($row['repairid'])?></span> </div> 
        <?php } ?>
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">执行人：</label>
        <span class="weui-form-preview__value">
			<?php 
			if(!empty($row['manageid'])){
				$m_str=$row['manageid'];
				$m_arr=explode(",",$m_str);
				foreach($m_arr as $key=>$val){
					echo ' <i class="fa  fa-user-o red"></i>      '.getManage($val);
				}
			}
			?>
        
        </span> </div>
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">任务时间：</label>
        <span class="weui-form-preview__value"><i  class="fa fa-play green"></i>          <?php echo date("Y-m-d H:i:s",$row['begintime']). "  
		<br/><i  class=' red fa  fa-stop'></i>     ". date("Y-m-d H:i:s",$row['endtime'])?></span> </div>
              <div class="weui-form-preview__item">
        <label class="weui-form-preview__label red">当前进度：</label>
        <span class="weui-form-preview__value red"><b><?php echo getJinDuName($row['jindu'])?></b></span> 
        </div>
    </div>
    <div class="weui-form-preview__ft op"> <?php echo $op_str?> </div>
     <input type="hidden" name="manageid"  id="manageid" value="<?php echo $manageid;?>">
  </div>
  <!--工单详情结束-->
  
  <?php }?>
  
  <!--工单列表结束--> 
</div>
		<div class="page-div">

        <?php echo $dopage->GetList(); ?>

        </div>
<div class="clear"></div>
<div class="sub_btn"></div>
<script src="lib/jquery-2.1.4.js"></script> 
<script src="lib/fastclick.js"></script> 
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
  $(function() {
    FastClick.attach(document.body);
  });

  function jiedan(id){
	  var manageid=$("#manageid").val();
	  $.ajax({
		  type: 'POST',
		  url: "op.php",
		  data: {id:id,op:'jiedan','manageid':manageid},
		  dataType: 'JSON',
		  success:function(result){
		  console.log(result);
			if(result.errno==0){
				 console.log(result.msg);
				if(result.msg==="ok"){
					$.toast("接单成功", function() {
					 //window.location.reload();
					 window.location.href="morder.php?jindu=4";
					});
					
				}else{
					 $.alert("接单失败，下手要快哦", "温馨提示");
				}
			}
		  }
	  });
	  
  }
  // 微信jssdk 
  wx.config({
    debug: false,
    appId: '<?php echo $signPackage["appId"];?>',
    timestamp: <?php echo $signPackage["timestamp"];?>,
    nonceStr: '<?php echo $signPackage["nonceStr"];?>',
    signature: '<?php echo $signPackage["signature"];?>',
    jsApiList: [
      // 所有要调用的 API 都要加到这个列表中
	    'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
		'openAddress',
		'chooseImage',
		'previewImage',
		'uploadImage',
		'downloadImage',
		'openLocation',
		'getLocation'
    ]
  });
  wx.ready(function () {
  //打开导航
	  $("#daohang").on("click",function(){  
	  		var orderid=$(this).data("orderid");
			  $.ajax({
			  type: 'POST',
			  url: "dingwei.php",
			  data: {op:'dingwei','id':orderid},
			  dataType: 'JSON',
			  success:function(result){
			  console.log(result);
				if(result.errno==0){
					 console.log(result.msg);
					if(result.msg==="ok"){
							  wx.openLocation({
								latitude: result.data.latitude, // 纬度，浮点数，范围为90 ~ -90
								longitude: result.data.longitude, // 经度，浮点数，范围为180 ~ -180。
								name: result.data.school, // 位置名
								address: result.data.sheng+result.data.shi+result.data.qu+result.data.address, // 地址详情说明
								scale: result.data.accuracy, // 地图缩放级别,整形值,范围从1~28。默认为最大
								infoUrl: 'https://www.hanzhibo.cn/wx/morder.php' // 在查看位置界面底部显示的超链接,可点击跳转
							});
					}else{
						 $.alert("获取位置失败，客户没有进行定位", "温馨提示");
					}
				}
			  }
		  });
	})	  

})
  
</script> 
<script src="js/jquery-weui.js"></script> 
<?php require_once('footer.php'); ?>